package com.andoridtools.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.andoridtools.R;


/**
 * 自定义对话框
 */

public class DefineDialog {


    public static Dialog DefineDialog(Context context, int layoutId) {
        Dialog dialog = new Dialog(context, R.style.Theme_Light_NoTitle_Dialog);
        dialog.setContentView(layoutId);
        //设置dialog大小
        Window dialogWindow = dialog.getWindow();
        WindowManager manager = ((Activity) context).getWindowManager();
        WindowManager.LayoutParams params = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        dialogWindow.setGravity(Gravity.CENTER);
        Display d = manager.getDefaultDisplay(); // 获取屏幕宽、高度
        params.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65，根据实际情况调整
        dialogWindow.setAttributes(params);

        return dialog;
    }


}
